 //发现页接口

import {http} from '@/utils/httpRequest'


// 获取圈子列表
export const getCircles = () => {
	let url = '/wx/v1/circle/circles';  
    return http({
        method: 'GET',
        url: url,
    })
}
// 获取圈子详情
export const getCircleDetail = (params) => {
	let url = `/wx/v1/circle/circle?circle_id=${params.circle_id}`;  
    return http({
        method: 'GET',
        url: url,
    })
}

// 关注圈子
export const postJoinCircle = (data) => {
	let url = '/wx/v1/circle/joinCircle';  
    return http({
        method: 'POST',
        url: url,
		data
    })
}

// 搜索圈子
export const postSearchCircle = (data) => {
	let url = '/wx/v1/post/searchCircle';  
    return http({
        method: 'POST',
        url: url,
		data
    })
}
//新建圈子
export const postNewCircle = (data) => {
	console.log(data);
   return new Promise((resolve, reject) => {
   	 uni.uploadFile({
   		url: '/api/v1/admin/addCircle', //仅为示例，非真实的接口地址
   		filePath: data.avatar[0].url,
   		name: 'circle_avatar',
   		formData: {
			circle_name:data.circle_name,
   			circle_description:data.circle_description,
   		},
   		success: (res) => {
			let result= JSON.parse(res.data)
			uni.showLoading({
				title: '加载中'
			});
			if(result.code === 1000){
				uni.hideLoading();
				uni.showToast({
					icon:"success",
					title: '创建成功',
					duration: 2000
				});
				setTimeout(()=>{
					uni.switchTab({ url: '/pages/circle/circle' })
				},2000);
			}
			else if(result.code === 1005){
				uni.hideLoading();
				uni.showToast({
					icon:"error",
					title: result.data,
					duration: 2000
				});
			}
   		},
   		fail: (error) => {
   			console.log(error);
   		}
   	});
   });
}